package cn.xianshu.web.controller;

import cn.xianshu.coursedto.CourseDoc;
import cn.xianshu.searchDto.CourseSearchDto;
import cn.xianshu.service.ICourseESService;
import cn.xianshu.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/es/course")
public class CourseESController {

    @Autowired
    private ICourseESService courseESService;

    /**
     * 面包屑
     * @param dto
       @return
     */
    @PostMapping("/searchCourse")
    public AjaxResult crumbs(@RequestBody CourseSearchDto dto){
        return AjaxResult.me().setResultObj(courseESService.crumbs(dto));
    }

    /**
     * 添加
     * @param doc
     * @return
     */
    @PreAuthorize("hasAuthority('es:course:save')")
    @PostMapping("/save")
    public AjaxResult save(@RequestBody CourseDoc doc){
        courseESService.save(doc);
        return AjaxResult.me();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('es:course:remove')")
    @DeleteMapping("/remove")
    public AjaxResult remove(@RequestParam Long id){
        courseESService.remove(id);
        return AjaxResult.me();
    }
}
